 /******************************************************************************
  * @file    PT32X005_i2c.h
  * @author  应用开发团队
  * @version V1.1.0
  * @date    2020/1/27
  * @brief    This file contains all the functions prototypes for the I2C firmware library.
  *
  ******************************************************************************
  * @attention
  *
  *
  *****************************************************************************/


/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef PT32X005_I2C_H
#define PT32X005_I2C_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "PT32X005.h"


/** @addtogroup I2C
  * @{
  */

/* Exported types ------------------------------------------------------------*/


/** @brief  I2C Init structure definition **/
typedef struct
{
  u32 I2C_BC_SEL;    /*!< Specifies the I2C mode.
                                         This parameter can be a value of @ref I2C_mode*/
  u32 I2C_ADDR_VAL;          /*!< Specifies the device own address 1.
                                         This parameter can be a 7-bit or 10-bit address*/
  u32 I2C_ACK_SEL;          /*!< Enables or disables the acknowledgement.
                                         This parameter can be a value of @ref I2C_acknowledgement*/
  u32 I2C_BR_VAL;            /*!< IIC frequency division: minimum 20, maximum 4096*/
}I2C_InitTypeDef;



/** @defgroup IS_I2C_ALL_PERIPH **/
#define IS_I2C_ALL_PERIPH(PERIPH)       ((PERIPH) == I2C)

/** @defgroup IS_I2C_BC_SEL **/
#define IS_I2C_BC_SEL(SEL)	(((SEL) == I2C_BC_Enable) || \
							((SEL) == I2C_BC_Disable))

/** @defgroup I2C_acknowledgement **/
#define IS_I2C_ACK_SEL(SEL)	(((SEL) == I2C_ACK_Enable) || \
							((SEL) == I2C_ACK_Disable))

/** @defgroup I2C_Prescaler **/
#define IS_I2C_BR_VAL(Value)	(((Value) >= 5)  && ((Value) < 1024))

/** @defgroup IS_I2C_ADDR_VAL **/
#define IS_I2C_ADDR_VAL(Value)   ((Value) <128)

/** @defgroup I2C_acknowledgement **/
#define IS_I2C_SR_SEL(SEL)	(((SEL) == I2C_Stop) || \
							((SEL) == I2C_StartOk) || \
							((SEL) == I2C_ReStartOk) || \
							((SEL) == I2C_MAS_GetAck_W) || \
							((SEL) == I2C_MAS_GetNack_W) || \
							((SEL) == I2C_MDS_GetAck) || \
							((SEL) == I2C_MDS_GetNack) || \
							((SEL) == I2C_MAS_SendAck_R) || \
							((SEL) == I2C_MAS_SendNack_R) || \
							((SEL) == I2C_MDG_SendAck) || \
							((SEL) == I2C_MDG_SendNack) || \
							((SEL) == I2C_SAG_SendAck_W) || \
							((SEL) == I2C_SAL_AG_SendAck_W) || \
							((SEL) == I2C_SBCAG_SendAck) || \
							((SEL) == I2C_SAL_BCAG_SendAck) || \
							((SEL) == I2C_SDG_SendAck) || \
							((SEL) == I2C_SDG_SendNack) || \
							((SEL) == I2C_SBCDG_SendAck) || \
							((SEL) == I2C_SBCDG_SendNack) || \
							((SEL) == I2C_SDG_GSRS) || \
							((SEL) == I2C_SAG_SendAck_R) || \
							((SEL) == I2C_SAL_AG_SendAck_R) || \
							((SEL) == I2C_SDS_ReadAck) || \
							((SEL) == I2C_SDS_ReadNack) || \
							((SEL) == I2C_SDSSA_GSRS) || \
							((SEL) == I2C_IDLE))


/* Exported macro ------------------------------------------------------------*/
/* Exported functions ---------------------------------------------------------*/
void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct);
void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct);
void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_SendData(I2C_TypeDef* I2Cx, u8 Data);
void I2C_SendAddr(I2C_TypeDef* I2Cx, u8 Data);
u8 I2C_ReceiveData(I2C_TypeDef* I2Cx);
FlagStatus I2C_GetStatus(I2C_TypeDef* I2Cx, u16 I2C_FLAG);
/**
  * @}
  */


#ifdef __cplusplus
}
#endif

#endif


